<?php

namespace app\models;

use app\core\components\Tree;
use Yii;

/**
 * This is the model class for table "{{%post_cate}}".
 *
 * @property integer $id
 * @property string $name
 * @property integer $pid
 * @property integer $sort
 * @property integer $icon
 */
class PostCate extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%post_cate}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['pid', 'sort', 'icon'], 'integer'],
            [['name'], 'string', 'max' => 20],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'name' => '分类名称',
            'pid' => '上级分类',
            'sort' => '排序',
            'icon' => '图标',
        ];
    }

    public static function treeArr() {
        $menus = static::find()->asArray()->all();
        $treeObj = new Tree($menus);
        return $treeObj->getTree();
    }

}
